#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import logging
import sys
from logging.handlers import TimedRotatingFileHandler


def get_logger(name, log_to_file=False):
    log_formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(message)s',
                                      datefmt='%Y-%m-%d %H:%M:%S')
    logger = logging.getLogger(name)

    logger.setLevel(logging.DEBUG)

    if (log_to_file):
        file_handler = TimedRotatingFileHandler('/home/liusen/IdeaWorkspace/wechat-jump/logs/log.txt',
                                                when="d",
                                                interval=1,
                                                backupCount=10)

        file_handler.setFormatter(log_formatter)
        logger.addHandler(file_handler)

    console_handler = logging.StreamHandler(stream=sys.stdout)
    console_handler.setFormatter(log_formatter)
    logger.addHandler(console_handler)

    return logger
